package com.xbongbong.saas.enums.product;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author WuHB
 * @date 2021/11/17 16:24
 */
@Getter
public enum ReceiptOrderServiceEnum {

    // 服务项目名称、服务项目编号、单位、单价、折扣（%）、售价（元）、数量、售价小计（元）

    // 产品
    PRODUCT(SelectProductEnum.PRODUCT.getAttr(), "enum.receiptOrderProduct.attrName.productName", "product", FieldTypeEnum.LINK_DATA.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 1),
    // 销售单位
    UNIT(SelectProductEnum.UNIT.getAttr(), "enum.receiptOrderProduct.attrName.basicUnit", "unit", SelectProductEnum.UNIT.getFieldType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 0),
    // 数量
    NUM(SelectProductEnum.NUM.getAttr(), SelectProductEnum.NUM.getSaasAttr(), SelectProductEnum.NUM.getI18nAttrName(), SelectProductEnum.NUM.getFieldType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 1),
    // 单价
    PRICE(SelectProductEnum.PRICE.getAttr(), SelectProductEnum.PRICE.getSaasAttr(), SelectProductEnum.PRICE.getI18nAttrName(), SelectProductEnum.PRICE.getFieldType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 0),
    // 折扣
    DISCOUNT(SelectProductEnum.DISCOUNT.getAttr(), SelectProductEnum.DISCOUNT.getSaasAttr(), SelectProductEnum.DISCOUNT.getI18nAttrName(), SelectProductEnum.DISCOUNT.getFieldType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 1),
    // 售价小计
    SUBTOTAL(SelectProductEnum.SUBTOTAL.getAttr(), SelectProductEnum.SUBTOTAL.getSaasAttr(), "enum.receiptOrderProduct.attrName.subtotal", SelectProductEnum.SUBTOTAL.getFieldType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 0),
    // 成本
    COST(SelectProductEnum.COST.getAttr(), SelectProductEnum.COST.getSaasAttr(), SelectProductEnum.COST.getAttrName(), FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 0),
    // 成本小计
    TOTAL_COST(SelectProductEnum.TOTAL_COST.getAttr(), SelectProductEnum.TOTAL_COST.getSaasAttr(), SelectProductEnum.TOTAL_COST.getAttrName(), FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 0),
    // 备注
    MEMO(SelectProductEnum.MEMO.getAttr(), SelectProductEnum.MEMO.getSaasAttr(), SelectProductEnum.MEMO.getI18nAttrName(), SelectProductEnum.MEMO.getFieldType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 1, 0),
    ;

    ReceiptOrderServiceEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable, Integer editHide, Integer showType, Integer visible, Integer required) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.visible = visible;
        this.required = required;
    }

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 英文名称
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     */
    private Integer showType;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    /**
     * 获取修改时不可见的字段
     *
     * @return 修改时不可见的字段
     */
    public static List<String> getUpdataInvisibleAttrList() {
        return Arrays.asList(COST.getAttr(), TOTAL_COST.getAttr());
    }

    public static List<String> getNonEditableList() {
        return Arrays.asList(PRODUCT.getAttr(), UNIT.getAttr(), COST.getAttr(), TOTAL_COST.getAttr());
    }

    public static String[] getProductScreen() {
        return new String[]{ProductEnum.NAME.getAttr(), ProductEnum.SERIALNO.getAttr(), ProductEnum.SPECIFICATION.getAttr(), ProductEnum.STOCK.getAttr(), ProductEnum.UNIT.getAttr()};
    }
}
